package com.zcxy.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcxy.anotation.Log;
import com.zcxy.core.bean.PageQuery;
import com.zcxy.core.bean.Response;
import com.zcxy.sys.entity.SysAutocode;
import com.zcxy.sys.pojo.SysAutocodeVo;
import com.zcxy.sys.service.ISysAutocodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/**
 * @author zcc
 * @version 1.0.0
 * @ClassName "SysAutocode"Controller.java
 * @Description "代码生成"
 * @createTime 2020-09-12
 */
@RestController
    @RequestMapping("/api/sysAutocode")
@Api(tags = "代码生成管理")
@Slf4j
public class SysAutocodeController {
    @Autowired
    private ISysAutocodeService iSysAutocodeService;

    @Log("获取代码生成数据--分页")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(代码生成)分页数据列表", notes = "获取(代码生成)分页数据列表")
    public Response<IPage<SysAutocodeVo>> queryPageList(@RequestBody PageQuery<SysAutocode> queryVo) {
        return Response.ok(iSysAutocodeService.queryPageList(queryVo));
    }

    @Log("获取代码生成数据-列表")
    @GetMapping(value = "/queryList")
    @ApiOperation(value = "获取代码生成数据-列表", notes = "获取代码生成数据-列表")
    public Response<List<SysAutocodeVo>> queryList() {
        return Response.ok(iSysAutocodeService.queryList());
    }


    @Log("添加代码生成数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "添加代码生成数据", notes = "添加代码生成数据/更新和新增一起")
    public Response<SysAutocode> addSysAutocode(@RequestBody @Validated @NotNull SysAutocode queryVo) {

        return Response.ok(iSysAutocodeService.addSysAutocode(queryVo));
    }

    @Log("添加代码生成数据")
    @GetMapping(value = "/view")
    @ApiOperation(value = "添加代码生成数据", notes = "添加代码生成数据/更新和新增一起")
    public Response<SysAutocodeVo> viewSysAutocode(@RequestParam String   id) {
        return Response.ok(iSysAutocodeService.viewSysAutocode(id));
    }



    @Log(value = "批量删除代码生成")
    @ApiOperation("批量删除代码生成")
    @DeleteMapping("/dels")
    public Response deleteByIds(@RequestBody List<String> ids) {
        iSysAutocodeService.removeAllSysAutocode(ids);
        return Response.ok();
    }


    @Log("代码生成")
    @ApiOperation("代码生成")
    @GetMapping(value = "/genCode")
    public void genCode(@RequestParam(name = "codeId")  String codeId,HttpServletResponse httpServletResponse) throws IOException {
            iSysAutocodeService.genCode(codeId,httpServletResponse);
    }



    @Log("获取表名")
    @ApiOperation("获取表名")
    @GetMapping(value = "/getTables")
    public Response<List<SysAutocode>> getTables(@RequestParam(name = "tableName",required = false) String tableName)  {
      return   Response.ok(iSysAutocodeService.getAllTables(tableName));
    }


}
